cd "D:\"
import excel "Data.xlsx", sheet("Data_ThirdEx") firstrow clear

label define Group 1"1.低信任,无问责" 2"1.低信任,问责" 3"1.高信任,无问责" 4"1.高信任,问责"
encode Group, gen(Group1) label(Group)

label define eval1 1"非常不同意" 2"不同意" 3"既不同意也不反对" 4"同意" 5"非常同意"
label define eval2 1"非常不同意" 2"不同意" 3"既不同意也不反对" 4"同意" 5"非常同意"
label define eval3 1"非常不同意" 2"不同意" 3"既不同意也不反对" 4"同意" 5"非常同意"

encode eval1, gen(eval11) label(eval1)
encode eval2, gen(eval21) label(eval2)
encode eval3, gen(eval31) label(eval3)

destring satisf, replace
destring trustscore, replace

encoder gender , replace setzero

label define age  1 "0-20岁" 2 "21-30岁" 3 "31-40岁" 4 "41-50岁" 5 "51-60岁" 6 "60岁以上"
encode age, gen(age1) label(age)

label define affiliation 0 "无业" 1 "全日制学生" 2 "党政机关" 3 "事业单位" 4 "国有企业" 5 "私营企业" 6 "外资企业" 7 "个体工商户" 8 "务农"  10"其他"  9"自由职业【提示：如作家、股票投资】"
encode affiliation, gen(affiliation1) label(affiliation)

label define politics 0 "群众" 1 "共青团员" 2 "中共党员" 3 "民主党派"
encode politics , gen(politics1) label(politics)

label define education 0 "小学及以下" 1 "初中" 2 "高中（含中专、技校、职高）" 3  "大专" 4   "大学本科" 5 "硕士" 6"博士"
encode education , gen(education1) label(education)

label define hukou 0 "农业户口" 1 "非农业户口" 2"没有户口"
encode hukou , gen(hukou1) label(hukou)

label define income 1 "5000元以下" 2 "5000-9999元" 3 "10,000-19,999元" 4 "20,000-29,999元" 5 "30,000-39,999元" 6 "40,000-49,999元" 7 "50,000-59,999元" 8 "60,000-79,999元" 9 "80,000-99,999元" 10 "100,000-119,999元" 11 "120,000-139,999元" 12 "140,000-159,999元" 13 "160,000-179,000元" 14 "180,000-199,999元" 15 "200,000-299,999元" 16"30万元以上"
encode income , gen(income1) label(income)

label define Ver 0"材料中没有相关的信息" 1"汉东省政府对南山市相关责任单位和责任人进行问责" 2"汉东省政府要求各地贯彻生态优先、绿色发展的理念" 3"汉东省政府向南山市派出督察组"

encode Ver, gen(Ver1) label(Ver)

drop age affiliation education politics hukou income eval1 eval2 eval3 Group Ver
rename (age1 affiliation1 education1 politics1 hukou1 income1 eval11 eval21 eval31 Ver1 Group1) (age affiliation education politics hukou income eval1 eval2 eval3 Ver Group)

gen eval = (eval1 + eval2 + eval3 ) / 3

gen trust = 0
replace trust = 1 if Group <= 2

gen sanction = 1
replace sanction = 0 if Group == 1 | Group == 3 

norm eval, method(mmx)
norm satisf, method(mmx)

*Descriptive Statistics
foreach v of var gender age politics income affiliation hukou education{
	logout, save (table_`v') excel replace: tab `v'
}

*Balance check
foreach v of var gender age politics income affiliation hukou education{
	ttest `v', by (sanction)
	ttest `v', by (trust)
}

*Modeling
reg mmx_eval i.sanction i.trust
outreg2 using D:\Resultsofexperiment2.xls, replace bdec(3) tdec(3) ctitle(eval) e(r2_a,F) addstat(F test,e(p)) alpha(0.001, 0.01, 0.05)

reg mmx_satisf i.sanction i.trust
outreg2 using D:\Resultsofexperiment2.xls, append bdec(3) tdec(3) ctitle(satisf) e(r2_a,F) addstat(F test,e(p)) alpha(0.001, 0.01, 0.05)

reg mmx_eval i.sanction i.trust i.gender i.age i.politics i.income i.affiliation i.hukou i.education
outreg2 using D:\Resultsofexperiment2.xls, append bdec(3) tdec(3) ctitle(eval) e(r2_a,F) addstat(F test,e(p)) alpha(0.001, 0.01, 0.05)

reg mmx_eval i.sanction##i.trust
outreg2 using D:\Resultsofexperiment2.xls, append bdec(3) tdec(3) ctitle(eval) e(r2_a,F) addstat(F test,e(p)) alpha(0.001, 0.01, 0.05)


*Average treatment effect
label define lab_sanction 0"without sanction" 1"with sanction"
label values sanction lab_sanction
label define lab_trust 0 "high trust" 1"low trust"
label values trust lab_trust

sum mmx_eval if sanction==0 & trust==0
sum mmx_eval if sanction==0 & trust==1
sum mmx_eval if sanction==1 & trust==0
sum mmx_eval if sanction==1 & trust==1

catcibar mmx_eval ,over(sanction) by(trust) legend(position(6) rows(3)) ///
ytitle("Blame avoidance effect",size(mlarge)) wrapxlab(3) xlabel(none,noticks) xscale(off) ///
xsize(5) ysize(4) ///
xtitle(n=100		 ///
n=100		 ///
n=100		 ///
n=100) scheme(s1mono)